package task3

import grails.test.mixin.TestFor
/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(Department)
class DepartmentTests {

    void testConstrains() {

        def dep_1 = new Department(name: 'Department1')
        mockForConstraintsTests(Department)

        assertTrue dep_1.validate()

        dep_1.save()
         assertEquals 1, Department.list().size()

        def dep_2 = new Department(name: 'Department1')

        assertFalse dep_2.validate()
        assertEquals 'unique', dep_2.errors['name']

        dep_2.name=''
        assertFalse dep_2.validate()
        assertEquals 'blank',dep_2.errors['name']


        dep_2.name='Dp'
        assertFalse dep_2.validate()
        assertEquals 'size',dep_2.errors['name']

        dep_2.name='D'*21
        assertFalse dep_2.validate()
        assertEquals 'size',dep_2.errors['name']

        dep_2.name = 'Department2'
        assertTrue dep_2.validate()

        dep_2.save()

        assertEquals 2, Department.list().size()

    }
}
